package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.personal.treasure.AddScoreReq;
import com.homedo.odin.solution.contract.personal.treasure.LevelRuleResp;
import com.homedo.odin.solution.contract.personal.treasure.PrivilegeResp;
import com.homedo.odin.solution.contract.personal.treasure.ScoreLevelResp;
import com.homedo.odin.solution.contract.personal.treasure.ScoreRuleResp;
import com.homedo.odin.solution.model.dto.ScoreLevelPrivilege;
import com.homedo.odin.solution.service.bizservice.personal.CommonBizService;
import com.homedo.odin.solution.service.bizservice.personal.UserTreasureBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhaoxudong
 * @date: 2018/3/7 10:47
 * @Description:
 */
@Api(description = "积分", tags = {"Treasure"},
        produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/user_treasure")
public class UserTreasureController extends BaseController<UserTreasureBizService> {

    @Autowired
    CommonBizService commonBizService;

    @ApiOperation(value = "PC_获取用户积分与等级",
            notes = "获取用户积分与等级",
            response = ScoreLevelResp.class)
    @GetMapping("/score_level/{userId}/{token}")
    public ResultData getScoreLevel(@ApiParam("用户id") @PathVariable("userId") Integer userId,
            @ApiParam("用户token") @PathVariable("token") String token) {
        ScoreLevelResp resp = baseService.getScoreLevel(userId, token);
        logger.info("获取用户积分与等级返回值:{}", resp.toJson());
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_获取等级规则", notes = "获取等级规则", response = LevelRuleResp.class)
    @GetMapping("/level_rule")
    public ResultData getLevelRule() {
        LevelRuleResp resp = baseService.getLevelRule();
        logger.info("获取等级规则返回值:{}", resp.toJson());
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_获取特权列表",
            notes = "获取特权列表",
            response = PrivilegeResp.class)
    @GetMapping("/privilege")
    public ResultData getPrivilege() {
        PrivilegeResp resp = baseService.getPrivilege();
        logger.info("获取特权返回值:{}", resp.toJson());
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_获取用户等级特权",
            notes = "获取用户等级特权",
            response = ScoreLevelPrivilege.class)
    @GetMapping("/privilege/{userId}")
    public ResultData getPrivilegeByUserId(@ApiParam("用户id") @PathVariable("userId") Integer userId) {
        ScoreLevelPrivilege resp = baseService.getPrivilegeByUserId(userId);
        logger.info("获取特权返回值:{}", resp.toJson());
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_积分获取机制",
            notes = "积分获取机制",
            response = ScoreRuleResp.class)
    @GetMapping("/score_rule/{userId}")
    public ResultData getScoreRule(@ApiParam("用户") @PathVariable("userId") Integer userId) {
        ScoreRuleResp resp = baseService.getScoreRule(userId);
        logger.info("积分获取机制返回值:{}", resp.toJson());
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_增加积分", notes = "增加积分")
    @PostMapping("/score")
    public ResultData score(@RequestBody AddScoreReq request) {
        commonBizService.addScore(request);
        return ResultData.newInstance();
    }
}
